package com.example.deertrip.tools_class;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;

import com.example.deertrip.Login_main_activity;
import com.example.deertrip.MainActivity;
import com.example.deertrip.R;

public class UserStateGet {
    public int canbuy=0;

    public void vlidate(Activity activity){

        SharedPreferences sp= activity.getSharedPreferences("deertrip", Context.MODE_PRIVATE);
        int login_stat=sp.getInt("login_state",0);

        if(login_stat==0){
            canbuy=1;
            AlertDialog.Builder builder = new AlertDialog.Builder(activity);
            builder.setTitle("提示");
            builder.setMessage("亲爱的鹿途旅客，您还没有登录！");
            builder.setIcon(R.drawable.deer);
            builder.setPositiveButton("前往登录页面", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    Intent intent = new Intent(activity, Login_main_activity.class);
                    activity.startActivity(intent);
                }


            });
            builder.create().show();
        }
    }

    public void login_out(Activity activity){
        SharedPreferences sp= activity.getSharedPreferences("deertrip", Context.MODE_PRIVATE);
        int login_stat=sp.getInt("login_state",0);

        if(login_stat!=0){
            SharedPreferences.Editor editor=sp.edit();
            editor.putInt("login_state", 0);
            editor.commit();
            AlertDialog.Builder builder = new AlertDialog.Builder(activity);
            builder.setTitle("提示");
            builder.setMessage("退出登录成功！");
            builder.setIcon(R.drawable.deer);
            builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    Intent intent = new Intent(activity, MainActivity.class);
                    activity.startActivity(intent);
                }


            });
            builder.create().show();
        }
        else{
            AlertDialog.Builder builder = new AlertDialog.Builder(activity);
            builder.setTitle("提示");
            builder.setMessage("您还没有登录！");
            builder.setIcon(R.drawable.deer);
            builder.create().show();
        }
    }
}
